﻿<template>
  <div class="app-container">
    <div v-if="count" class="tableTitle">
      <span v-if="count.yesterday">昨日:{{ count.yesterday }}</span>
      <span v-else>昨日:_&nbsp;_</span>
      <span v-if="count.week_count">本周:{{ count.week_count }}</span>
      <span v-else>本周:_&nbsp;_</span>
      <span v-if="count.month_count">本月:{{ count.month_count }}</span>
      <span v-else>本月:_&nbsp;_</span>
      <span v-if="count.all_count">总计:{{ count.all_count }}</span>
      <span v-else>总计:_&nbsp;_</span>
    </div>
    <div class="filter-title">
      <el-form label-position="right" label-width="95px">
        <el-form-item :label="$t('videoData.time')+' :'">
          <div class="filter-item">
            <el-date-picker
              v-model="listQuery.startTime"
              :picker-options="pickerOptionsB"
              type="date"
              :placeholder="$t('public.startTime')"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
          <div class="filter-item">
            <el-date-picker
              v-model="listQuery.endTime"
              :picker-options="pickerOptionsE"
              type="date"
              :placeholder="$t('videoData.endTime')"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </el-form-item>
        <el-button
          style="margin-left: 20px;"
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          @click="handleFilter"
        >{{ $t('table.search') }}</el-button>
        <el-button
          style="margin-left: 10px"
          class="filter-item"
          type="primary"
          @click="handleRefresh"
        >{{ $t('table.refresh') }}</el-button>
      </el-form>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      element-loading-text="拼命加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255,255,255,0.2)"
      border
      fit
      highlight-current-row
      style="width: 100%min-height:1000px"
    >
      <el-table-column fixed="left" align="center" :label="$t('table.id')" width="65">
        <template slot-scope="scope">
          <span>{{ (listQuery.page-1)*listQuery.limit+scope.$index+1 }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.time')">
        <template slot-scope="scope">
          <span>{{ scope.row.time }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.videoCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.video_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.playCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.play_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.viewCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.view_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.couponGetCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.coupon_get_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.couponUseCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.coupon_use_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.orderCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.order_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.orderPayCount')">
        <template slot-scope="scope">
          <span>{{ scope.row.order_pay_count }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip :label="$t('videoData.moneySum')">
        <template slot-scope="scope">
          <span>{{ scope.row.money_sum }}</span>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination
        background
        :current-page="listQuery.page"
        :page-sizes="[10,20,30,50]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: "VideoData",
  data() {
    return {
      showSearchItem: false,
      loading: false,
      tableKey: 0,
      list: null,
      total: null,
      count: undefined,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        startTime: "",
        endTime: ""
      },
      dialogStatus: "",
      textMap: {
        update: "更新",
        create: "添加",
        review: "审核",
        read: "查看"
      },
      pickerOptionsB: {
        // 限制时间
        // selectableRange: ['22:00:00 - 23:59:59','00:00:00 - 02:00:00'],
        // 限制日期
        disabledDate: this.disabledDateB
      },
      pickerOptionsE: {
        disabledDate: this.disabledDateE
      }
    };
  },
  computed: {
    operWidth: function() {
      return this.opreaterItem * 80 + "px";
    }
  },
  created() {
    this.getList();
  },
  methods: {
    disabledDateB(time) {
      if (this.listQuery.endTime) {
        return (
          time.getTime() >
          new Date(this.listQuery.endTime).getTime() + 24 * 3600 * 1000 - 8.64e7
        );
      }
    },
    disabledDateE(time) {
      if (this.listQuery.startTime) {
        return (
          time.getTime() < new Date(this.listQuery.startTime).getTime() - 8.64e6
        );
      }
    },
    getList() {
      this.listLoading = true;
      const data = {
        rows: this.listQuery.limit,
        page: this.listQuery.page
      };
      if (this.listQuery.startTime) {
        data["startTime"] = this.listQuery.startTime;
      }
      if (this.listQuery.endTime) {
        const date = new Date(this.listQuery.endTime);
        data["endTime"] = this.timestampToTime(
          date.getTime() + (60 * 60 * 24 * 1000 - 1)
        );
      }
      const adMasterIndexPath = {
        // 年月播放报表列表
        company: "STQ",
        api: "pc_VideoData_index",
        version: "1.0",
        data: data
      };
      this.socketApi.sendSock(JSON.stringify(adMasterIndexPath), res => {
        if (res) {
          if (res !== '{"type":"ping"}') {
            const resj = JSON.parse(res);
            if (resj.code === -1) {
              this.$message.error(resj.message);
            } else {
              this.total = resj.count;
              this.list = resj.data.data;
              this.count = {
                all_count: resj.data.all_count,
                month_count: resj.data.month_count,
                week_count: resj.data.week_count,
                yesterday: resj.data.yesterday
              };
            }
          }
          this.listLoading = false;
        } else {
          this.$message.error(" 获取商家档案列表失败 ");
          this.listLoading = false;
        }
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleRefresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        startTime: "",
        endTime: ""
      };
      this.getList();
    }
  }
};
</script>
